package com.example.modellol;

import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.viewpager.widget.ViewPager;
import com.example.modellol.adapter.HomeVpAdapter;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.tabs.TabLayout;



public class HomeActivity extends AppCompatActivity {
    private ViewPager mViewPager;
    private TabLayout bottomNav;
    private TextView set_Btn;

    private TextView t_1;
    private TextView t_2;
    private TextView t_3;
    private TextView t_4;
    private TextView t_5;
    private TextView t_6;
    private TextView t_7;


    private HomeVpAdapter mVpAdapter;
    private DrawerLayout rootView;
    private BottomNavigationView mBottomNavigationView;




    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_lol_main);
        find();
        initView();
        initEvent();
        page();
        onclick();
    }


    private void find() {
        rootView =findViewById(R.id.drawer_layout);
        mViewPager = findViewById(R.id.vp_content);
        bottomNav = findViewById(R.id.tab_news_top);
        mBottomNavigationView=findViewById(R.id.bnv_bottom_nav);
        set_Btn=findViewById(R.id.tv_setting_btn);
        t_1=findViewById(R.id.t_1);
        t_2=findViewById(R.id.t_2);
        t_3=findViewById(R.id.t_3);
        t_4=findViewById(R.id.t_4);
        t_5=findViewById(R.id.t_5);
        t_6=findViewById(R.id.t_6);
        t_7=findViewById(R.id.t_7);
    }

    private void onclick() {
        set_Btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(HomeActivity.this, "跳转成功", Toast.LENGTH_SHORT).show();
                Intent intent=new Intent();
                intent.setClass(HomeActivity.this,SettingActivity.class);
                intent.putExtra("data","HomeActivity");
                startActivity(intent);
            }
        });

        t_1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(HomeActivity.this, "跳转成功", Toast.LENGTH_SHORT).show();
            }
        });

        t_2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(HomeActivity.this, "跳转成功", Toast.LENGTH_SHORT).show();
            }
        });
        t_3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(HomeActivity.this, "跳转成功", Toast.LENGTH_SHORT).show();
            }
        });
        t_4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(HomeActivity.this, "跳转成功", Toast.LENGTH_SHORT).show();
            }
        });
        t_5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(HomeActivity.this, "跳转成功", Toast.LENGTH_SHORT).show();
            }
        });
        t_6.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(HomeActivity.this, "跳转成功", Toast.LENGTH_SHORT).show();
            }
        });
        t_7.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(HomeActivity.this, "跳转成功", Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void page() {
        mVpAdapter = new HomeVpAdapter(getSupportFragmentManager());
        mViewPager.setAdapter(mVpAdapter);
        bottomNav.setupWithViewPager(mViewPager);
    }

    private void initEvent() {
        mBottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.nav_five:
                        Intent intent=new Intent();
                        intent.setClass(HomeActivity.this,MineActivity.class);
                        startActivity(intent);
                        return true;
                    //  break;
                }
                return false;
            }
        });
    }



    protected void initView() {
        ImageView view= findViewById(R.id.img_user_head);

        view.setImageResource(R.drawable.number_1);

        findViewById(R.id.img_open).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                rootView.openDrawer(Gravity.START);
            }
        });
    }


    protected int contentView() {
        return R.layout.activity_lol_main;
    }
}
